
// const data=require('./mock/index')
// console.log(data)
const data = [
    {
        'username': 'admin',
        'password': 'admin',
    },
    {
        'username': 'abc',
        'password': '123',
    },
]
const bodyParser = require('body-parser')
const fs = require('fs')
module.exports = (app) => {
    app.use(bodyParser.json())
    // 表单
    app.post('/api/datajson', (req, res) => {
        const { data } = req.body
        //    console.log(data)
        fs.writeFileSync('./data.json', JSON.stringify(data))
        res.send({
            code: 200,
            mess: '发送成功'
        })
    })
    // 登录
    app.post('/api/long', (req, res) => {
        const { username, password } = req.body
        let ister = data.find(v => v.username === username && v.password === password)
        if (ister) {
            res.send({
                code: 200,
                token: 'xxxxx',
                mess: '登录成功'
            })
        } else {
            res.send({
                code: 404,
                mess: '登录失败'
            })
        }
    })
}